#include "MyBufferTemplate.h"
#include "MyBufferTemplate.h" // no error because "#pragma once"
#include "MySleep.h"

template <typename T>
void MyBuffer<T>::Put(T* p)
{
    std::unique_lock<std::mutex> aul(m_mutex);
    m_queue.push(p);
}

template <typename T>
T* MyBuffer<T>::Get()
{
    std::unique_lock<std::mutex> aul(m_mutex);
    while (m_queue.empty())
    {
        aul.unlock();
        MySleep(1);
        aul.lock();
    }
    T* p = m_queue.front();
    m_queue.pop();
    return p;
}

// must do explicit-instantiation for every use case
template class MyBuffer<int>;
template class MyBuffer<void>;
